{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a4115231-af72-405b-9e8e-5dc0d7988a3e",
   "metadata": {
    "id": "a4115231-af72-405b-9e8e-5dc0d7988a3e"
   },
   "source": [
    "# Mining through jira issues\n",
    "\n",
    "Superlinked combines the power of vector search - which enables finding similar issues to a query text or reference issue - with powerful filtering to empower a really versatile search over Jira issues."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "vU2pOzeuecTS",
   "metadata": {
    "id": "vU2pOzeuecTS"
   },
   "outputs": [],
   "source": [
    "%pip install superlinked==37.5.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "04fce6d8-1abe-400c-824d-6a65b046bbaf",
   "metadata": {
    "id": "04fce6d8-1abe-400c-824d-6a65b046bbaf"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "from typing import cast\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "from superlinked import framework as sl\n",
    "\n",
    "pd.set_option(\"display.max_columns\", 60)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f22513e-bf6a-44e7-95f9-dff2c48790d5",
   "metadata": {
    "id": "9f22513e-bf6a-44e7-95f9-dff2c48790d5"
   },
   "source": [
    "## Read and check data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "78fe31d5-3bf3-4f84-82e6-b4a419799cfc",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 556
    },
    "id": "78fe31d5-3bf3-4f84-82e6-b4a419799cfc",
    "outputId": "1d506b43-87b7-4c66-d03e-8e50710bb54f"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>type</th>\n",
       "      <th>status</th>\n",
       "      <th>priority</th>\n",
       "      <th>resolution</th>\n",
       "      <th>popularity</th>\n",
       "      <th>company</th>\n",
       "      <th>severity</th>\n",
       "      <th>comments</th>\n",
       "      <th>participants</th>\n",
       "      <th>has_attachment</th>\n",
       "      <th>versions_affected</th>\n",
       "      <th>duplicate_of</th>\n",
       "      <th>components</th>\n",
       "      <th>labels</th>\n",
       "      <th>referenced_by</th>\n",
       "      <th>references</th>\n",
       "      <th>blocks</th>\n",
       "      <th>blocked_by</th>\n",
       "      <th>causes</th>\n",
       "      <th>caused_by</th>\n",
       "      <th>fix_version</th>\n",
       "      <th>resolution_time</th>\n",
       "      <th>text</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SRCTREEWIN-12334</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>Low</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>symphonyai.com</td>\n",
       "      <td>2.0</td>\n",
       "      <td></td>\n",
       "      <td>[eb89d03d1ea4(JIRAUSER4541977)]</td>\n",
       "      <td>False</td>\n",
       "      <td>[3.2.2]</td>\n",
       "      <td>[SRCTREEWIN-2409]</td>\n",
       "      <td>[Git]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Code scroll not proper in horizontal way !imag...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SRCTREEWIN-12336</td>\n",
       "      <td>Suggestion</td>\n",
       "      <td>Gathering Interest</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>hotmail.com</td>\n",
       "      <td>NaN</td>\n",
       "      <td></td>\n",
       "      <td>[45603a355f99(jdemeyer1930161690)]</td>\n",
       "      <td>False</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[UX]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Names for patches When you create two patches ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SRCTREEWIN-12337</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>Low</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>efi.com</td>\n",
       "      <td>2.0</td>\n",
       "      <td></td>\n",
       "      <td>[2931c1386587(aloke.bordia1371316332)]</td>\n",
       "      <td>False</td>\n",
       "      <td>[3.2.4]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[General]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Cherry-pick does not provide an option to push...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SRCTREEWIN-12338</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>Low</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>bytecommerce.nl</td>\n",
       "      <td>2.0</td>\n",
       "      <td>26/Sep/2019 5:43 AM;157e9a1ee4cf;Wanted to ask...</td>\n",
       "      <td>[157e9a1ee4cf(roy.van.den.ekker)]</td>\n",
       "      <td>False</td>\n",
       "      <td>[3.2.4]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[Beta]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Git flow not automatically branching from corr...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SRCTREEWIN-12341</td>\n",
       "      <td>Bug</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>Low</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>wakeone.co</td>\n",
       "      <td>3.0</td>\n",
       "      <td></td>\n",
       "      <td>[93f49685815c(JIRAUSER4546844)]</td>\n",
       "      <td>False</td>\n",
       "      <td>[3.2.2]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[UX]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>NaN</td>\n",
       "      <td>The adjustable border line between staged and ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 id        type              status priority resolution  \\\n",
       "0  SRCTREEWIN-12334         Bug        Needs Triage      Low       None   \n",
       "1  SRCTREEWIN-12336  Suggestion  Gathering Interest     None       None   \n",
       "2  SRCTREEWIN-12337         Bug        Needs Triage      Low       None   \n",
       "3  SRCTREEWIN-12338         Bug        Needs Triage      Low       None   \n",
       "4  SRCTREEWIN-12341         Bug        Needs Triage      Low       None   \n",
       "\n",
       "   popularity          company  severity  \\\n",
       "0           0   symphonyai.com       2.0   \n",
       "1           0      hotmail.com       NaN   \n",
       "2           0          efi.com       2.0   \n",
       "3           0  bytecommerce.nl       2.0   \n",
       "4           0       wakeone.co       3.0   \n",
       "\n",
       "                                            comments  \\\n",
       "0                                                      \n",
       "1                                                      \n",
       "2                                                      \n",
       "3  26/Sep/2019 5:43 AM;157e9a1ee4cf;Wanted to ask...   \n",
       "4                                                      \n",
       "\n",
       "                             participants  has_attachment versions_affected  \\\n",
       "0         [eb89d03d1ea4(JIRAUSER4541977)]           False           [3.2.2]   \n",
       "1      [45603a355f99(jdemeyer1930161690)]           False                []   \n",
       "2  [2931c1386587(aloke.bordia1371316332)]           False           [3.2.4]   \n",
       "3       [157e9a1ee4cf(roy.van.den.ekker)]           False           [3.2.4]   \n",
       "4         [93f49685815c(JIRAUSER4546844)]           False           [3.2.2]   \n",
       "\n",
       "        duplicate_of components labels referenced_by references blocks  \\\n",
       "0  [SRCTREEWIN-2409]      [Git]     []            []         []     []   \n",
       "1                 []       [UX]     []            []         []     []   \n",
       "2                 []  [General]     []            []         []     []   \n",
       "3                 []     [Beta]     []            []         []     []   \n",
       "4                 []       [UX]     []            []         []     []   \n",
       "\n",
       "  blocked_by causes caused_by fix_version  resolution_time  \\\n",
       "0         []     []        []          []              NaN   \n",
       "1         []     []        []          []              NaN   \n",
       "2         []     []        []          []              NaN   \n",
       "3         []     []        []          []              NaN   \n",
       "4         []     []        []          []              NaN   \n",
       "\n",
       "                                                text  \n",
       "0  Code scroll not proper in horizontal way !imag...  \n",
       "1  Names for patches When you create two patches ...  \n",
       "2  Cherry-pick does not provide an option to push...  \n",
       "3  Git flow not automatically branching from corr...  \n",
       "4  The adjustable border line between staged and ...  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DATA_PATH: str = \"https://storage.googleapis.com/superlinked-notebook-jira-issue-discovery/issue_data.json\"\n",
    "issue_data = pd.read_json(DATA_PATH, lines=True)\n",
    "issue_data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5bad17e-1a7a-4d4b-9817-930353f9d37a",
   "metadata": {
    "id": "a5bad17e-1a7a-4d4b-9817-930353f9d37a"
   },
   "source": [
    "## Superlinked config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "93c5c9cd-9bd1-4762-af74-4f3ed56af5e7",
   "metadata": {
    "id": "93c5c9cd-9bd1-4762-af74-4f3ed56af5e7"
   },
   "outputs": [],
   "source": [
    "class Issue(sl.Schema):\n",
    "    id: sl.IdField\n",
    "    type: sl.String\n",
    "    status: sl.String\n",
    "    priority: sl.String | None\n",
    "    resolution: sl.String | None\n",
    "    popularity: sl.Integer\n",
    "    company: sl.String\n",
    "    severity: sl.Float | None\n",
    "    comments: sl.String\n",
    "    participants: sl.StringList\n",
    "    has_attachment: sl.String  # could be Boolean if NLQ supported it\n",
    "    versions_affected: sl.StringList\n",
    "    duplicate_of: sl.StringList\n",
    "    components: sl.StringList\n",
    "    labels: sl.StringList\n",
    "    referenced_by: sl.StringList\n",
    "    references: sl.StringList\n",
    "    blocks: sl.StringList\n",
    "    blocked_by: sl.StringList\n",
    "    causes: sl.StringList\n",
    "    caused_by: sl.StringList\n",
    "    fix_version: sl.StringList\n",
    "    resolution_time: sl.Float | None\n",
    "    text: sl.String\n",
    "\n",
    "\n",
    "issue = Issue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c7c815fb-aca6-49f2-9847-8886a36ef776",
   "metadata": {},
   "outputs": [],
   "source": [
    "unique_categories: dict[str, list[str]] = {\n",
    "    categorical_column_name: cast(list[str], issue_data[categorical_column_name].astype(str).dropna().unique().tolist())\n",
    "    for categorical_column_name in [\"status\", \"resolution\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "62d54c7b-05f4-4425-bc23-61cfbafdd86a",
   "metadata": {
    "id": "62d54c7b-05f4-4425-bc23-61cfbafdd86a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:08:26 superlinked.framework.dsl.index.index INFO   initialized index\n"
     ]
    }
   ],
   "source": [
    "MODELNAME: str = \"sentence-transformers/all-mpnet-base-v2\"\n",
    "\n",
    "comment_space = sl.TextSimilaritySpace(issue.comments, model=MODELNAME)\n",
    "text_space = sl.TextSimilaritySpace(issue.text, model=MODELNAME)\n",
    "\n",
    "popularity_space = sl.NumberSpace(issue.popularity, min_value=0.0, max_value=50, mode=sl.Mode.SIMILAR)\n",
    "severity_space = sl.NumberSpace(issue.severity, min_value=1.0, max_value=3.0, mode=sl.Mode.SIMILAR)\n",
    "resolution_time_space = sl.NumberSpace(issue.resolution_time, min_value=0.0, max_value=474, mode=sl.Mode.SIMILAR)\n",
    "\n",
    "status_space = sl.CategoricalSimilaritySpace(issue.status, categories=unique_categories[\"status\"])\n",
    "resolution_space = sl.CategoricalSimilaritySpace(issue.resolution, categories=unique_categories[\"resolution\"])\n",
    "\n",
    "issue_index = sl.Index(\n",
    "    spaces=[\n",
    "        comment_space,\n",
    "        text_space,\n",
    "        popularity_space,\n",
    "        severity_space,\n",
    "        resolution_time_space,\n",
    "        status_space,\n",
    "        resolution_space,\n",
    "    ],\n",
    "    fields=[\n",
    "        issue.status,\n",
    "        issue.priority,\n",
    "        issue.resolution,\n",
    "        issue.company,\n",
    "        issue.severity,\n",
    "        issue.participants,\n",
    "        issue.has_attachment,\n",
    "        issue.versions_affected,\n",
    "        issue.duplicate_of,\n",
    "        issue.components,\n",
    "        issue.labels,\n",
    "        issue.referenced_by,\n",
    "        issue.references,\n",
    "        issue.blocks,\n",
    "        issue.blocked_by,\n",
    "        issue.causes,\n",
    "        issue.caused_by,\n",
    "        issue.fix_version,\n",
    "    ],\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ec8a671f-edf4-4c3a-b05f-32595dd28880",
   "metadata": {
    "id": "ec8a671f-edf4-4c3a-b05f-32595dd28880"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:08:27 superlinked.framework.query.query_dag_evaluator INFO   initialized query dag\n",
      "11:08:27 superlinked.framework.online.online_dag_evaluator INFO   initialized entity dag\n",
      "11:08:27 superlinked.framework.dsl.executor.interactive.interactive_executor INFO   started in-memory app\n"
     ]
    }
   ],
   "source": [
    "df_parser = sl.DataFrameParser(issue)\n",
    "issue_source: sl.InMemorySource = sl.InMemorySource(issue, parser=df_parser)\n",
    "executor: sl.InMemoryExecutor = sl.InMemoryExecutor(sources=[issue_source], indices=[issue_index])\n",
    "app: sl.InMemoryApp = executor.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "O7XJBpU3IlU_",
   "metadata": {
    "id": "O7XJBpU3IlU_"
   },
   "source": [
    "### Ingest data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "35ae5160-66c1-4392-93a9-767581b797f9",
   "metadata": {
    "id": "35ae5160-66c1-4392-93a9-767581b797f9",
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:08:34 sentence_transformers.SentenceTransformer INFO   Load pretrained SentenceTransformer: sentence-transformers/all-mpnet-base-v2\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "746b809f0d8d4f8a9584ddac8c1ee36a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/18 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b26dbb7841ca4962bd2a229987b87abb",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/31 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:08:48 superlinked.framework.online.online_dag_evaluator INFO   evaluated entities\n",
      "11:08:48 superlinked.framework.online.source.online_data_processor INFO   stored input data\n"
     ]
    }
   ],
   "source": [
    "issue_source.put(issue_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76T4iECiIoVb",
   "metadata": {
    "id": "76T4iECiIoVb"
   },
   "source": [
    "## Run queries"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "JEEYCYqrIxvQ",
   "metadata": {
    "id": "JEEYCYqrIxvQ"
   },
   "source": [
    "### Simple filtering"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "EBDdX4PGI2Qd",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "EBDdX4PGI2Qd",
    "outputId": "998e31c5-f1ee-4c62-b85d-feffab1d318f"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:08:57 superlinked.framework.query.query_dag_evaluator INFO   evaluated query\n",
      "11:08:57 superlinked.framework.dsl.executor.query.query_executor INFO   executed query\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>priority</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Medium</td>\n",
       "      <td>SRCTREEWIN-13259</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Medium</td>\n",
       "      <td>SRCTREEWIN-13675</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Medium</td>\n",
       "      <td>SRCTREEWIN-13776</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  priority                id  similarity_score\n",
       "0   Medium  SRCTREEWIN-13259               0.0\n",
       "1   Medium  SRCTREEWIN-13675               0.0\n",
       "2   Medium  SRCTREEWIN-13776               0.0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we can filter for a priority string being equal\n",
    "filter_priority_query = (\n",
    "    sl.Query(issue_index)\n",
    "    .find(issue)\n",
    "    .filter(issue.priority == sl.Param(\"filter_priority\"))\n",
    "    .select(fields=[issue.priority])\n",
    "    .limit(3)\n",
    ")\n",
    "\n",
    "res_filter_priority = app.query(filter_priority_query, filter_priority=\"Medium\")\n",
    "sl.PandasConverter.to_pandas(res_filter_priority)  # 0.0 similarity as these are filter queries only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "tQisflHaJvF7",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "tQisflHaJvF7",
    "outputId": "320844d1-9559-44ce-8309-c48511293f78"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:08:58 superlinked.framework.query.query_dag_evaluator INFO   evaluated query\n",
      "11:08:58 superlinked.framework.dsl.executor.query.query_executor INFO   executed query\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>severity</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.0</td>\n",
       "      <td>SRCTREEWIN-12341</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.0</td>\n",
       "      <td>SRCTREEWIN-12345</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>SRCTREEWIN-12353</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   severity                id  similarity_score\n",
       "0       3.0  SRCTREEWIN-12341               0.0\n",
       "1       3.0  SRCTREEWIN-12345               0.0\n",
       "2       3.0  SRCTREEWIN-12353               0.0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# or a severity number being larger as well\n",
    "filter_severity_query = (\n",
    "    sl.Query(issue_index)\n",
    "    .find(issue)\n",
    "    .filter(issue.severity >= sl.Param(\"filter_severity\"))\n",
    "    .select(fields=[issue.severity])\n",
    "    .limit(3)\n",
    ")\n",
    "\n",
    "res_filter_severity = app.query(filter_severity_query, filter_severity=3.0)\n",
    "sl.PandasConverter.to_pandas(res_filter_severity)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5NtFScgFK5e4",
   "metadata": {
    "id": "5NtFScgFK5e4"
   },
   "source": [
    "### Vector search for similar issues with filters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0S9Q6FMbK0DS",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "0S9Q6FMbK0DS",
    "outputId": "f74e3a76-9478-4c0f-9076-49bb89028aea"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ac9d61ad815f460e939dec2a7efc4086",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:09:00 superlinked.framework.query.query_dag_evaluator INFO   evaluated query\n",
      "11:09:00 superlinked.framework.dsl.executor.query.query_executor INFO   executed query\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>severity</th>\n",
       "      <th>text</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Authentication failure - Keeps attempting to a...</td>\n",
       "      <td>SRCTREEWIN-13084</td>\n",
       "      <td>0.627935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Failed Authentication after account setup Hi,W...</td>\n",
       "      <td>SRCTREEWIN-13109</td>\n",
       "      <td>0.456589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Github basic login with PAT fails with unhelpf...</td>\n",
       "      <td>SRCTREEWIN-13321</td>\n",
       "      <td>0.351087</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   severity                                               text  \\\n",
       "0       3.0  Authentication failure - Keeps attempting to a...   \n",
       "1       3.0  Failed Authentication after account setup Hi,W...   \n",
       "2       3.0  Github basic login with PAT fails with unhelpf...   \n",
       "\n",
       "                 id  similarity_score  \n",
       "0  SRCTREEWIN-13084          0.627935  \n",
       "1  SRCTREEWIN-13109          0.456589  \n",
       "2  SRCTREEWIN-13321          0.351087  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we can find a special theme in severe issues using vector search\n",
    "severe_auth_failure_query = (\n",
    "    sl.Query(issue_index)\n",
    "    .find(issue)\n",
    "    .filter(issue.severity > sl.Param(\"filter_severity\"))\n",
    "    .similar(text_space, sl.Param(\"query_text\"))\n",
    "    .select(fields=[issue.severity, issue.text])\n",
    "    .limit(3)\n",
    ")\n",
    "\n",
    "res_severe_auth_failure = app.query(\n",
    "    severe_auth_failure_query, filter_severity=2.0, query_text=\"authentication failures\"\n",
    ")\n",
    "sl.PandasConverter.to_pandas(res_severe_auth_failure)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "rtkdhqDbOA72",
   "metadata": {
    "id": "rtkdhqDbOA72"
   },
   "source": [
    "### Search with natural language"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "R4DPXRGRGCr9",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 143
    },
    "id": "R4DPXRGRGCr9",
    "outputId": "b3b32be3-6cff-41f7-88a2-784472b4cf4d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:07:29 httpx INFO   HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
      "11:07:29 superlinked.framework.query.query_dag_evaluator INFO   evaluated query\n",
      "11:07:29 superlinked.framework.dsl.executor.query.query_executor INFO   executed query\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>severity</th>\n",
       "      <th>text</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Authentication failure - Keeps attempting to a...</td>\n",
       "      <td>SRCTREEWIN-13084</td>\n",
       "      <td>0.627935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Failed Authentication after account setup Hi,W...</td>\n",
       "      <td>SRCTREEWIN-13109</td>\n",
       "      <td>0.456589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Github basic login with PAT fails with unhelpf...</td>\n",
       "      <td>SRCTREEWIN-13321</td>\n",
       "      <td>0.351087</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   severity                                               text  \\\n",
       "0       3.0  Authentication failure - Keeps attempting to a...   \n",
       "1       3.0  Failed Authentication after account setup Hi,W...   \n",
       "2       3.0  Github basic login with PAT fails with unhelpf...   \n",
       "\n",
       "                 id  similarity_score  \n",
       "0  SRCTREEWIN-13084          0.627935  \n",
       "1  SRCTREEWIN-13109          0.456589  \n",
       "2  SRCTREEWIN-13321          0.351087  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "openai_config = sl.OpenAIClientConfig(api_key=os.environ[\"OPEN_AI_API_KEY\"], model=\"gpt-4o\")\n",
    "\n",
    "# we can find a special theme in severe issues using vector search\n",
    "nlq_severe_auth_failure_query = (\n",
    "    sl.Query(issue_index)\n",
    "    .find(issue)\n",
    "    .filter(issue.severity >= sl.Param(\"filter_severity\"))\n",
    "    .similar(text_space, sl.Param(\"query_text\"))\n",
    "    .with_natural_query(sl.Param(\"natural_query\"), openai_config)\n",
    "    .select(fields=[issue.severity, issue.text])\n",
    "    .limit(3)\n",
    ")\n",
    "\n",
    "res_nlq_severe_auth_failure = app.query(\n",
    "    nlq_severe_auth_failure_query, natural_query=\"high severity authentication failures\"\n",
    ")\n",
    "sl.PandasConverter.to_pandas(res_nlq_severe_auth_failure)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ALrlHFAfN_8O",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "ALrlHFAfN_8O",
    "outputId": "4e8b0e22-4d52-412d-d609-e608fd0a77a5"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'filter_severity': 3.0, 'query_text': 'authentication failures'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show relevant extracted seach params\n",
    "relevant_params = [\"filter_severity\", \"query_text\"]\n",
    "{key: value for key, value in res_nlq_severe_auth_failure.metadata.search_params.items() if key in relevant_params}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "gKLvd3F5PNQw",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 363
    },
    "id": "gKLvd3F5PNQw",
    "outputId": "16bacf47-f52b-47f6-9fd4-b278c57d40e6"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:07:33 httpx INFO   HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "19ad4d74bda1497897760cde9f5cdd41",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Batches:   0%|          | 0/1 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:07:33 superlinked.framework.query.query_dag_evaluator INFO   evaluated query\n",
      "11:07:33 superlinked.framework.dsl.executor.query.query_executor INFO   executed query\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>severity</th>\n",
       "      <th>text</th>\n",
       "      <th>versions_affected</th>\n",
       "      <th>status</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Sourctree closes after \"Checkout in Sourctree\"...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13125</td>\n",
       "      <td>0.479753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Git - Enabling \"Push all tags to remotes\" will...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13363</td>\n",
       "      <td>0.478067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Open remote - URL customization In our company...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13254</td>\n",
       "      <td>0.462704</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>\"Check out in Sourctree\" always tries to clone...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13126</td>\n",
       "      <td>0.422688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Different branch folders are merged anyway Hi!...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13438</td>\n",
       "      <td>0.413081</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Github basic login with PAT fails with unhelpf...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13321</td>\n",
       "      <td>0.394501</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Subtree Dissappears from Stash after Reopening...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13288</td>\n",
       "      <td>0.390878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Issues when trtying to Authenticate. Everytime...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13720</td>\n",
       "      <td>0.385265</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Same name of repos If you have same names of r...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13329</td>\n",
       "      <td>0.334843</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Resolve Conflicts -&gt; Mine/Theirs when popping ...</td>\n",
       "      <td>[3.3.9]</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13799</td>\n",
       "      <td>0.326965</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   severity                                               text  \\\n",
       "0       3.0  Sourctree closes after \"Checkout in Sourctree\"...   \n",
       "1       3.0  Git - Enabling \"Push all tags to remotes\" will...   \n",
       "2       3.0  Open remote - URL customization In our company...   \n",
       "3       3.0  \"Check out in Sourctree\" always tries to clone...   \n",
       "4       3.0  Different branch folders are merged anyway Hi!...   \n",
       "5       3.0  Github basic login with PAT fails with unhelpf...   \n",
       "6       3.0  Subtree Dissappears from Stash after Reopening...   \n",
       "7       3.0  Issues when trtying to Authenticate. Everytime...   \n",
       "8       3.0  Same name of repos If you have same names of r...   \n",
       "9       3.0  Resolve Conflicts -> Mine/Theirs when popping ...   \n",
       "\n",
       "  versions_affected        status                id  similarity_score  \n",
       "0           [3.3.9]  Needs Triage  SRCTREEWIN-13125          0.479753  \n",
       "1           [3.3.9]  Needs Triage  SRCTREEWIN-13363          0.478067  \n",
       "2           [3.3.9]  Needs Triage  SRCTREEWIN-13254          0.462704  \n",
       "3           [3.3.9]  Needs Triage  SRCTREEWIN-13126          0.422688  \n",
       "4           [3.3.9]  Needs Triage  SRCTREEWIN-13438          0.413081  \n",
       "5           [3.3.9]  Needs Triage  SRCTREEWIN-13321          0.394501  \n",
       "6           [3.3.9]  Needs Triage  SRCTREEWIN-13288          0.390878  \n",
       "7           [3.3.9]  Needs Triage  SRCTREEWIN-13720          0.385265  \n",
       "8           [3.3.9]  Needs Triage  SRCTREEWIN-13329          0.334843  \n",
       "9           [3.3.9]  Needs Triage  SRCTREEWIN-13799          0.326965  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# and the situation can be a lot more sophisticated as well\n",
    "severity_version_status_natural_query = (\n",
    "    sl.Query(issue_index)\n",
    "    .find(issue)\n",
    "    .similar(text_space, sl.Param(\"query_text\"))\n",
    "    .filter(issue.severity >= sl.Param(\"filter_severity\"))\n",
    "    .filter(issue.versions_affected.contains(sl.Param(\"filter_version\")))\n",
    "    .filter(issue.status == sl.Param(\"filter_status\"))\n",
    "    .with_natural_query(sl.Param(\"natural_query\"), openai_config)\n",
    "    .select(fields=[issue.severity, issue.text, issue.versions_affected, issue.status])\n",
    "    .limit(10)\n",
    ")\n",
    "\n",
    "sophisticated_natural_query: str = \"\"\"\n",
    "    high severity, git, Bitbucket, or version control related\n",
    "    issues that affect version 3.3.9 and triage is needed\"\"\"\n",
    "\n",
    "res_severity_version_status_natural = app.query(\n",
    "    severity_version_status_natural_query,\n",
    "    natural_query=sophisticated_natural_query,\n",
    ")\n",
    "sl.PandasConverter.to_pandas(res_severity_version_status_natural)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "APukXc6ZQeYc",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "APukXc6ZQeYc",
    "outputId": "d4b12953-9b37-4dc6-ef64-de01ca2abf30"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'query_text': 'git, Bitbucket, or version control related issues',\n",
       " 'filter_severity': 3.0,\n",
       " 'filter_version': ['3.3.9'],\n",
       " 'filter_status': 'Needs Triage'}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show relevant extracted seach params\n",
    "relevant_params = [\"filter_severity\", \"query_text\", \"filter_version\", \"filter_status\"]\n",
    "{\n",
    "    key: value\n",
    "    for key, value in res_severity_version_status_natural.metadata.search_params.items()\n",
    "    if key in relevant_params\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "j_C69AGJVblA",
   "metadata": {
    "id": "j_C69AGJVblA"
   },
   "source": [
    "### Finding similar issue to a specific issue"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "p_jfOG21VWbm",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "p_jfOG21VWbm",
    "outputId": "34431a04-0843-43f5-d180-67c9f9b29440"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:07:33 superlinked.framework.query.query_dag_evaluator INFO   evaluated query\n",
      "11:07:33 superlinked.framework.dsl.executor.query.query_executor INFO   executed query\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>severity</th>\n",
       "      <th>text</th>\n",
       "      <th>popularity</th>\n",
       "      <th>status</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "      <th>resolution_time</th>\n",
       "      <th>resolution</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Code scroll not proper in horizontal way !imag...</td>\n",
       "      <td>0</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-12334</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Hidden scrollbar on the History tab Greetings,...</td>\n",
       "      <td>4</td>\n",
       "      <td>Closed</td>\n",
       "      <td>SRCTREEWIN-12356</td>\n",
       "      <td>0.861396</td>\n",
       "      <td>387.0</td>\n",
       "      <td>Cannot Reproduce</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Subwindow drap and drop can not be dropped at ...</td>\n",
       "      <td>0</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13482</td>\n",
       "      <td>0.818760</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Scrolling to bottom of file content pane freez...</td>\n",
       "      <td>1</td>\n",
       "      <td>Closed</td>\n",
       "      <td>SRCTREEWIN-13225</td>\n",
       "      <td>0.804471</td>\n",
       "      <td>127.0</td>\n",
       "      <td>Fixed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Sourcetree hangs when I mousewheel on the diff...</td>\n",
       "      <td>0</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13318</td>\n",
       "      <td>0.789222</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Nonenglish encoding display error There is a p...</td>\n",
       "      <td>0</td>\n",
       "      <td>Gathering Impact</td>\n",
       "      <td>SRCTREEWIN-13872</td>\n",
       "      <td>0.786665</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2.0</td>\n",
       "      <td>SourceTree not showing the diff just says 'sel...</td>\n",
       "      <td>2</td>\n",
       "      <td>Short Term Backlog</td>\n",
       "      <td>SRCTREEWIN-13959</td>\n",
       "      <td>0.784653</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2.0</td>\n",
       "      <td>File list displays in reverse alphabetical ord...</td>\n",
       "      <td>0</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-14153</td>\n",
       "      <td>0.782129</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Issue with local repositories and tabs at star...</td>\n",
       "      <td>0</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13717</td>\n",
       "      <td>0.775956</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Issue with local repositories and tabs at star...</td>\n",
       "      <td>0</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>SRCTREEWIN-13719</td>\n",
       "      <td>0.775956</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   severity                                               text  popularity  \\\n",
       "0       2.0  Code scroll not proper in horizontal way !imag...           0   \n",
       "1       2.0  Hidden scrollbar on the History tab Greetings,...           4   \n",
       "2       2.0  Subwindow drap and drop can not be dropped at ...           0   \n",
       "3       2.0  Scrolling to bottom of file content pane freez...           1   \n",
       "4       2.0  Sourcetree hangs when I mousewheel on the diff...           0   \n",
       "5       2.0  Nonenglish encoding display error There is a p...           0   \n",
       "6       2.0  SourceTree not showing the diff just says 'sel...           2   \n",
       "7       2.0  File list displays in reverse alphabetical ord...           0   \n",
       "8       2.0  Issue with local repositories and tabs at star...           0   \n",
       "9       2.0  Issue with local repositories and tabs at star...           0   \n",
       "\n",
       "               status                id  similarity_score  resolution_time  \\\n",
       "0        Needs Triage  SRCTREEWIN-12334          1.000000              NaN   \n",
       "1              Closed  SRCTREEWIN-12356          0.861396            387.0   \n",
       "2        Needs Triage  SRCTREEWIN-13482          0.818760              NaN   \n",
       "3              Closed  SRCTREEWIN-13225          0.804471            127.0   \n",
       "4        Needs Triage  SRCTREEWIN-13318          0.789222              NaN   \n",
       "5    Gathering Impact  SRCTREEWIN-13872          0.786665              NaN   \n",
       "6  Short Term Backlog  SRCTREEWIN-13959          0.784653              NaN   \n",
       "7        Needs Triage  SRCTREEWIN-14153          0.782129              NaN   \n",
       "8        Needs Triage  SRCTREEWIN-13717          0.775956              NaN   \n",
       "9        Needs Triage  SRCTREEWIN-13719          0.775956              NaN   \n",
       "\n",
       "         resolution  \n",
       "0               NaN  \n",
       "1  Cannot Reproduce  \n",
       "2               NaN  \n",
       "3             Fixed  \n",
       "4               NaN  \n",
       "5               NaN  \n",
       "6               NaN  \n",
       "7               NaN  \n",
       "8               NaN  \n",
       "9               NaN  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's find a similar issue, but assign weights to different attributes\n",
    "similar_issues_query = (\n",
    "    sl.Query(\n",
    "        issue_index,\n",
    "        weights={\n",
    "            text_space: 1.0,\n",
    "            comment_space: 0.0,\n",
    "            popularity_space: 1.0,\n",
    "            severity_space: 1.0,\n",
    "            resolution_time_space: 0.0,\n",
    "            status_space: 0.0,\n",
    "            resolution_space: 0.0,\n",
    "        },\n",
    "    )\n",
    "    .find(issue)\n",
    "    .with_vector(issue, sl.Param(\"issue_id\"))\n",
    "    .select(\n",
    "        fields=[\n",
    "            issue.severity,\n",
    "            issue.text,\n",
    "            issue.popularity,\n",
    "            issue.severity,\n",
    "            issue.resolution_time,\n",
    "            issue.status,\n",
    "            issue.resolution,\n",
    "        ]\n",
    "    )\n",
    "    .limit(10)\n",
    ")\n",
    "\n",
    "res_similar_issues = app.query(similar_issues_query, issue_id=\"SRCTREEWIN-12334\")\n",
    "sl.PandasConverter.to_pandas(res_similar_issues)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "RT1HCiNATI0R",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "RT1HCiNATI0R",
    "outputId": "a950ce0b-ae55-41c7-86ac-509501fbc17a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11:07:36 httpx INFO   HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
      "11:07:38 httpx INFO   HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
      "11:07:38 superlinked.framework.query.query_dag_evaluator INFO   evaluated query\n",
      "11:07:38 superlinked.framework.dsl.executor.query.query_executor INFO   executed query\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "      <th>status</th>\n",
       "      <th>severity</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Code scroll not proper in horizontal way !imag...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-12334</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Subwindow drap and drop can not be dropped at ...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-13482</td>\n",
       "      <td>0.818760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Sourcetree hangs when I mousewheel on the diff...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-13318</td>\n",
       "      <td>0.789222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>File list displays in reverse alphabetical ord...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-14153</td>\n",
       "      <td>0.782129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Issue with local repositories and tabs at star...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-13717</td>\n",
       "      <td>0.775956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Issue with local repositories and tabs at star...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-13719</td>\n",
       "      <td>0.775956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Diff not working on UTF-16 LE files without BO...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-12976</td>\n",
       "      <td>0.771097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Maximized SourceTree window covers taskbar whe...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-13976</td>\n",
       "      <td>0.770757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Cannot unstage hunk While viewing in-app diff ...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-13540</td>\n",
       "      <td>0.768646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Support CR as a line break in diff views Some ...</td>\n",
       "      <td>Needs Triage</td>\n",
       "      <td>2.0</td>\n",
       "      <td>SRCTREEWIN-13878</td>\n",
       "      <td>0.765955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                text        status  severity  \\\n",
       "0  Code scroll not proper in horizontal way !imag...  Needs Triage       2.0   \n",
       "1  Subwindow drap and drop can not be dropped at ...  Needs Triage       2.0   \n",
       "2  Sourcetree hangs when I mousewheel on the diff...  Needs Triage       2.0   \n",
       "3  File list displays in reverse alphabetical ord...  Needs Triage       2.0   \n",
       "4  Issue with local repositories and tabs at star...  Needs Triage       2.0   \n",
       "5  Issue with local repositories and tabs at star...  Needs Triage       2.0   \n",
       "6  Diff not working on UTF-16 LE files without BO...  Needs Triage       2.0   \n",
       "7  Maximized SourceTree window covers taskbar whe...  Needs Triage       2.0   \n",
       "8  Cannot unstage hunk While viewing in-app diff ...  Needs Triage       2.0   \n",
       "9  Support CR as a line break in diff views Some ...  Needs Triage       2.0   \n",
       "\n",
       "                 id  similarity_score  \n",
       "0  SRCTREEWIN-12334          1.000000  \n",
       "1  SRCTREEWIN-13482          0.818760  \n",
       "2  SRCTREEWIN-13318          0.789222  \n",
       "3  SRCTREEWIN-14153          0.782129  \n",
       "4  SRCTREEWIN-13717          0.775956  \n",
       "5  SRCTREEWIN-13719          0.775956  \n",
       "6  SRCTREEWIN-12976          0.771097  \n",
       "7  SRCTREEWIN-13976          0.770757  \n",
       "8  SRCTREEWIN-13540          0.768646  \n",
       "9  SRCTREEWIN-13878          0.765955  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# and we can combine that with natural language search too\n",
    "similar_issues_filtered_query = (\n",
    "    sl.Query(\n",
    "        issue_index,\n",
    "        weights={\n",
    "            text_space: 1.0,\n",
    "            comment_space: 0.0,\n",
    "            popularity_space: 1.0,\n",
    "            severity_space: 1.0,\n",
    "            resolution_time_space: 0.0,\n",
    "            status_space: 0.0,\n",
    "            resolution_space: 0.0,\n",
    "        },\n",
    "    )\n",
    "    .find(issue)\n",
    "    .with_vector(issue, sl.Param(\"issue_id\"))\n",
    "    .filter(issue.status == sl.Param(\"filter_status\"))\n",
    "    .with_natural_query(sl.Param(\"natural_query\"), openai_config)\n",
    "    .select(fields=[issue.text, issue.status, issue.severity])\n",
    "    .limit(10)\n",
    ")\n",
    "\n",
    "res_similar_issues_filtered = app.query(\n",
    "    similar_issues_filtered_query, natural_query=\"similar issues to SRCTREEWIN-12334 that need triage\"\n",
    ")\n",
    "sl.PandasConverter.to_pandas(res_similar_issues_filtered)"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "gpuType": "T4",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "superlinked_venv",
   "language": "python",
   "name": "superlinked_venv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
